--package declaration
	package prims is
		procedure add(a,b: in bit_vector; cin: in bit;
								sum: out bit_vector; cout: out bit);
		function inc(x : bit_vector) return bit_vector;
		function dec(x : bit_vector) return bit_vector;
		function intval(val: bit_vector) return integer;
	end prims;
--package initialization
	package body prims is
		procedure add(a,b: in bit_vector; cin: in bit;
								sum: out bit_vector; cout: out bit)is
			variable sumv, av, bv: bit_vector(a'length-1 downto 0);
			variable carry: bit;
		begin
			av := a;
			bv := b;
			carry := cin;
			for i in 0 to sumv'high loop
				sumv(i) := av(i) xor bv(i) xor carry;
				carry := (av(i) and bv(i)) or (av(i) and carry)
							or (bv(i) and carry);
			end loop;
			cout := carry;
			sum := sumv;
		end add;
		function inc(x: bit_vector) return bit_vector is
			variable xv: bit_vector(x'length-1 downto 0);
		begin
			xv := x;
			for i in 0 to xv'high loop
				if xv(i) = '0' then
					xv(i) := '1';
					exit;
				else xv(i) := '0';
				end if;
			end loop;
			return xv;
		end inc;
		function dec(x: bit_vector) return bit_vector is
			variable xv: bit_vector(x'length-1 downto 0);
		begin
			xv := x;
			for i in 0 to xv'high loop
				if xv(i) = '1' then
					xv(i) := '0';
					exit;
				else xv(i) := '1';
				end if;
			end loop;
			return xv;
		end dec;
		function intval(val: bit_vector) return integer is
			variable valv: bit_vector(val'length-1 downto 0);
			variable sum: integer := 0;
		begin
			valv := val;
			for n in valv'low to valv'high loop
				if valv(n) = '1' then
					sum := sum + (2**n);
				end if;
			end loop;
			return sum;
		end intval;
	end prims;